<?php
class Districts extends Admin_Controller
{
    function __construct()
    {
        parent::__construct();
    }
    
    function index(){
         $data['districts'] = new District();
         $data['districts']->order_by('id','asc')->get_page();
         $this->template->append_metadata(js_lightbox());
         $this->template->append_metadata(js_checkbox('approve'));
         $this->template->build('admin/district_index',$data);
    }
    
    function form($id=FALSE){
        $data['district'] = new District($id);
        $this->template->build('admin/district_form',$data);
    }
    
    function save($id=FALSE){
        if($_POST){
            $district = new District($id);
            if(!$id)$_POST['user_id'] = $this->session->userdata('id');
            $district->from_array($_POST);
            $district->save();
            set_notify('success', lang('save_data_complete'));
        }
        redirect('district_infos/admin/districts');
    }
    
    function approve($id)
    {
        if($_POST)
        {
            $district = new District($id);
            $_POST['approve_id'] = $this->session->userdata('id');
            $district->approve_date = date("Y-m-d H:i:s");
            $district->from_array($_POST);
            $district->save();
            echo approve_comment($district);
        }
    }
}
?>